{ Siberian Olympiad. 2 stage.
  Problemset: http://agul-problems1.googlecode.com/svn/trunk/2010-2011/wso/stage2/wso_2stage.pdf
  Problem 4.
  Points: 100
}
var n,cur,res,current:int64; i:longint; check:boolean;
begin
 reset(input,'input.txt');
 rewrite(output,'output.txt');
readln(n);
cur:=n-1;
res:=0;
while (res=0) and (cur>1) do begin
  if ((n-1) mod cur=0) then begin
    check:=false;
    current:=n;
    i:=0;
    while (i<cur) and (check=false) do begin
      inc(i);
      if (current-1) mod cur<>0 then check:=true;
      current:=current - current div cur -1;
    end;
    if check=false then begin
      res:=cur;
    end;
  end;
  dec(cur);
end;
writeln(res);
end.